<template>
  <div>
    <van-cell title="搜索历史">
      <div v-if="isDeleteShow">
        <!-- 全部删除方式1-splice -->
        <!-- <span @click="searchHistories.splice(0, searchHistories.length)">全部删除</span> -->
        <span @click="$emit('clear-search-histories')">全部删除</span>
        &nbsp;&nbsp;
        <span @click="isDeleteShow = false">完成</span>
      </div>
      <van-icon name="delete-o" v-else @click="isDeleteShow = true" />
    </van-cell>
    <van-cell
      :title="item"
      v-for="(item, index) in searchHistories"
      :key="index"
      @click="onItemClick(item, index)"
    >
      <van-icon name="close" v-show="isDeleteShow"></van-icon>
    </van-cell>
  </div>
</template>

<script>
export default {
  name: 'SearchHistory',
  props: {
    searchHistories: {
      type: Array,
      required: true
    }
  },
  components: {},
  data () {
    return {
      isDeleteShow: false
    }
  },
  created () {},
  mounted () {},
  methods: {
    onItemClick (item, index) {
      if (this.isDeleteShow) {
        // 删除
        this.searchHistories.splice(index, 1)
      } else {
        // 搜索
        this.$emit('search', item)
      }
    }
  },
  watch: {},
  computed: {}
}
</script>

<style lang="less" scoped>
</style>
